home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Tools / ClassAct / Examples / Glyph / GlyphExample.c < prev    next >
C/C++ Source or Header  |  1997-04-27  |  9KB  |  320 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <intuition/intuition.h>
  5. #include <intuition/gadgetclass.h>
  6. #include <intuition/imageclass.h>
  7. #include <intuition/icclass.h>
  8. #include <gadgets/listbrowser.h>
  9. #include <images/label.h>
  10. #include <libraries/asl.h>
  11. #include <libraries/gadtools.h>
  12. #include <utility/tagitem.h>
  13. #include <proto/asl.h>
  14. #include <proto/dos.h>
  15. #include <proto/diskfont.h>
  16. #include <proto/exec.h>
  17. #include <proto/gadtools.h>
  18. #include <proto/graphics.h>
  19. #include <proto/icon.h>
  20. #include <proto/intuition.h>
  21. #include <proto/utility.h>
  22. #include <proto/wb.h>
  23. #include <classact.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26.  
  27.  
  28. /* Here's where it all starts.
  29.  */
  30. main()
  31. {
  32.     struct Screen *screen = NULL;
  33.  
  34.     if (!ButtonBase) return(20);
  35.  
  36.     /* We'll just open up on the default public screen, and use its screen font.
  37.      */
  38.     if (screen = LockPubScreen(NULL))
  39.     {
  40.         struct DrawInfo *drinfo = GetScreenDrawInfo(screen);
  41.         Object *layout;
  42.  
  43.         if (layout = LayoutObject,
  44.                         GA_DrawInfo, drinfo,
  45.                         LAYOUT_DeferLayout, TRUE,    /* Layout refreshes done on
  46.                                                      * task's context (by the
  47.                                                      * window class) */
  48.                         LAYOUT_SpaceOuter, TRUE,
  49.                         LAYOUT_AddChild, LayoutObject,
  50.                             LAYOUT_VertAlignment, LAYOUT_ALIGN_TOP,
  51.                             LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  52.                             LAYOUT_BevelStyle, BVS_GROUP,
  53.                             LAYOUT_Label, "Available Glyphs",
  54.  
  55.                             LAYOUT_AddChild, LayoutObject,
  56.                                 LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  57.                                 LAYOUT_HorizAlignment, LAYOUT_ALIGN_RIGHT,
  58.                                 LAYOUT_SpaceOuter, TRUE,
  59.     
  60.                                 LAYOUT_AddImage, GlyphObject,
  61.                                     GLYPH_Glyph, GLYPH_DOWNARROW,
  62.                                     GlyphEnd,
  63.                                     CHILD_MinWidth, 12,
  64.                                     CHILD_MinHeight, 12,
  65.                                     CHILD_Label, LabelObject,
  66.                                         LABEL_Text, "Down Arrow:",
  67.                                         LabelEnd,
  68.     
  69.                                 LAYOUT_AddImage, GlyphObject,
  70.                                     GLYPH_Glyph, GLYPH_UPARROW,
  71.                                     GlyphEnd,
  72.                                     CHILD_MinWidth, 12,
  73.                                     CHILD_MinHeight, 12,
  74.                                     CHILD_Label, LabelObject,
  75.                                         LABEL_Text, "Up Arrow:",
  76.                                         LabelEnd,
  77.     
  78.                                 LAYOUT_AddImage, GlyphObject,
  79.                                     GLYPH_Glyph, GLYPH_LEFTARROW,
  80.                                     GlyphEnd,
  81.                                     CHILD_MinWidth, 12,
  82.                                     CHILD_MinHeight, 12,
  83.                                     CHILD_Label, LabelObject,
  84.                                         LABEL_Text, "Left Arrow:",
  85.                                         LabelEnd,
  86.     
  87.                                 LAYOUT_AddImage, GlyphObject,
  88.                                     GLYPH_Glyph, GLYPH_RIGHTARROW,
  89.                                     GlyphEnd,
  90.                                     CHILD_MinWidth, 12,
  91.                                     CHILD_MinHeight, 12,
  92.                                     CHILD_Label, LabelObject,
  93.                                         LABEL_Text, "Right Arrow:",
  94.                                         LabelEnd,
  95.     
  96.                                 LAYOUT_AddImage, GlyphObject,
  97.                                     GLYPH_Glyph, GLYPH_DROPDOWN,
  98.                                     GlyphEnd,
  99.                                     CHILD_MinWidth, 12,
  100.                                     CHILD_MinHeight, 12,
  101.                                     CHILD_Label, LabelObject,
  102.                                         LABEL_Text, "Drop Down:",
  103.                                         LabelEnd,
  104.     
  105.                                 LAYOUT_AddImage, GlyphObject,
  106.                                     GLYPH_Glyph, GLYPH_CHECKMARK,
  107.                                     GlyphEnd,
  108.                                     CHILD_MinWidth, 12,
  109.                                     CHILD_MinHeight, 12,
  110.                                     CHILD_Label, LabelObject,
  111.                                         LABEL_Text, "Check Mark:",
  112.                                         LabelEnd,
  113.     
  114.                                 LAYOUT_AddImage, GlyphObject,
  115.                                     GLYPH_Glyph, GLYPH_RADIOBUTTON,
  116.                                     GlyphEnd,
  117.                                     CHILD_MinWidth, 12,
  118.                                     CHILD_MinHeight, 12,
  119.                                     CHILD_Label, LabelObject,
  120.                                         LABEL_Text, "Radio Button:",
  121.                                         LabelEnd,
  122.                                 LayoutEnd,
  123.     
  124.                             LAYOUT_AddChild, LayoutObject,
  125.                                 LAYOUT_SpaceOuter, TRUE,
  126.                                 LAYOUT_AddImage, BevelObject,
  127.                                     GA_DrawInfo, drinfo,
  128.                                     BEVEL_Style, BVS_SBAR_HORIZ,
  129.                                     BevelEnd,
  130.                                 LayoutEnd,
  131.                                 CHILD_MinWidth, 4,
  132.                                 CHILD_WeightedWidth, 0,
  133.  
  134.                             LAYOUT_AddChild, LayoutObject,
  135.                                 LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  136.                                 LAYOUT_VertAlignment, LAYOUT_ALIGN_CENTER,
  137.                                 LAYOUT_SpaceOuter, TRUE,
  138.     
  139.                                 LAYOUT_AddImage, GlyphObject,
  140.                                     GLYPH_Glyph, GLYPH_POPUP,
  141.                                     GlyphEnd,
  142.                                     CHILD_MinWidth, 12,
  143.                                     CHILD_MinHeight, 12,
  144.                                     CHILD_Label, LabelObject,
  145.                                         LABEL_Text, "Pop Up:",
  146.                                         LabelEnd,
  147.     
  148.                                 LAYOUT_AddImage, GlyphObject,
  149.                                     GLYPH_Glyph, GLYPH_POPFONT,
  150.                                     GlyphEnd,
  151.                                     CHILD_MinWidth, 12,
  152.                                     CHILD_MinHeight, 12,
  153.                                     CHILD_Label, LabelObject,
  154.                                         LABEL_Text, "Pop Font:",
  155.                                         LabelEnd,
  156.     
  157.                                 LAYOUT_AddImage, GlyphObject,
  158.                                     GLYPH_Glyph, GLYPH_POPFILE,
  159.                                     GlyphEnd,
  160.                                     CHILD_MinWidth, 12,
  161.                                     CHILD_MinHeight, 12,
  162.                                     CHILD_Label, LabelObject,
  163.                                         LABEL_Text, "Pop File:",
  164.                                         LabelEnd,
  165.     
  166.                                 LAYOUT_AddImage, GlyphObject,
  167.                                     GLYPH_Glyph, GLYPH_POPDRAWER,
  168.                                     GlyphEnd,
  169.                                     CHILD_MinWidth, 12,
  170.                                     CHILD_MinHeight, 12,
  171.                                     CHILD_Label, LabelObject,
  172.                                         LABEL_Text, "Pop Drawer:",
  173.                                         LabelEnd,
  174.     
  175.                                 LAYOUT_AddImage, GlyphObject,
  176.                                     GLYPH_Glyph, GLYPH_POPSCREENMODE,
  177.                                     GlyphEnd,
  178.                                     CHILD_MinWidth, 12,
  179.                                     CHILD_MinHeight, 12,
  180.                                     CHILD_Label, LabelObject,
  181.                                         LABEL_Text, "Pop Screen Mode:",
  182.                                         LabelEnd,
  183.     
  184.                                 LAYOUT_AddImage, GlyphObject,
  185.                                     GLYPH_Glyph, GLYPH_POPTIME,
  186.                                     GlyphEnd,
  187.                                     CHILD_MinWidth, 12,
  188.                                     CHILD_MinHeight, 12,
  189.                                     CHILD_Label, LabelObject,
  190.                                         LABEL_Text, "Pop Time:",
  191.                                         LabelEnd,
  192.     
  193.                                 LAYOUT_AddImage, GlyphObject,
  194.                                     GLYPH_Glyph, GLYPH_RETURNARROW,
  195.                                     GlyphEnd,
  196.                                     CHILD_MinWidth, 12,
  197.                                     CHILD_MinHeight, 12,
  198.                                     CHILD_Label, LabelObject,
  199.                                         LABEL_Text, "Return Arrow:",
  200.                                         LabelEnd,
  201.                                 LayoutEnd,
  202.                             LayoutEnd,
  203.                         LayoutEnd)
  204.         {
  205.             struct MsgPort *app_port;
  206.             Object *window_obj;
  207.  
  208.             /* Create a message port for App* messages.  This is needed for
  209.              * iconification.  We're being a touch naughty by not checking
  210.              * the return code, but that just means that iconification won't
  211.              * work, nothing really bad will happen.
  212.              */
  213.             app_port = CreateMsgPort();
  214.  
  215.             /* Create the window object.
  216.              */
  217.             if (window_obj = WindowObject,
  218.                                 WA_Left, 0,
  219.                                 WA_Top, screen->Font->ta_YSize + 3,
  220.                                 WA_CustomScreen, screen,
  221.                                 WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
  222.                                 WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET |
  223.                                             WFLG_SIZEGADGET | WFLG_ACTIVATE | WFLG_SMART_REFRESH,
  224.                                 WA_Title, "Glyph class example",
  225.                                 WA_NewLookMenus, TRUE,
  226.                                 WINDOW_ParentGroup, layout,
  227.                                 WINDOW_IconifyGadget, TRUE,
  228.                                 WINDOW_Icon, GetDiskObject("PROGDIR:GlyphExample"),
  229.                                 WINDOW_IconTitle, "GlyphExample",
  230.                                 WINDOW_AppPort, app_port,
  231.                                 TAG_DONE))
  232.             {
  233.                 struct Window *win;
  234.  
  235.                 /*  Open the window.
  236.                  */
  237.                 if (win = (struct Window *)CA_OpenWindow(window_obj))
  238.                 {
  239.                     ULONG signal;
  240.                     BOOL ok = TRUE;
  241.  
  242.                     /* Obtain the window wait signal mask.
  243.                      */
  244.                     GetAttr(WINDOW_SigMask, window_obj, &signal);
  245.  
  246.                     /* Input Event Loop
  247.                      */
  248.                     while (ok)
  249.                     {
  250.                         ULONG result;
  251.  
  252.                         Wait(signal | (1L << app_port->mp_SigBit));
  253.  
  254.                         /* CA_HandleInput() returns the gadget ID of a clicked
  255.                          * gadget, or one of several pre-defined values.  For
  256.                          * this demo, we're only actually interested in a
  257.                          * close window and a couple of gadget clicks.
  258.                          */
  259.                         while ((result = CA_HandleInput(window_obj, NULL)) != WMHI_LASTMSG)
  260.                         {
  261.                             switch(result & WMHI_CLASSMASK)
  262.                             {
  263.                                 case WMHI_CLOSEWINDOW:
  264.                                     ok = FALSE;
  265.                                     break;
  266.  
  267.                                 case WMHI_GADGETUP:
  268.                                     switch (result & WMHI_GADGETMASK)
  269.                                     {
  270.                                         default:
  271.                                             break;
  272.                                     }
  273.                                     break;
  274.  
  275.                                 case WMHI_ICONIFY:
  276.                                     if (CA_Iconify(window_obj))
  277.                                         win = NULL;
  278.                                     break;
  279.                              
  280.                                 case WMHI_UNICONIFY:
  281.                                     win = CA_OpenWindow(window_obj);
  282.                                     break;
  283.  
  284.                                 default:
  285.                                     break;
  286.                             }
  287.                         }
  288.                     }
  289.                  }
  290.                 else
  291.                     PutStr("ERROR: failed to start.  Couldn't open window\n");
  292.  
  293.                 /* Disposing of the window object will also close the
  294.                  * window if it is already opened and it will dispose of
  295.                  * all objects attached to it.
  296.                  */
  297.                 DisposeObject(window_obj);
  298.             }
  299.             else
  300.                 PutStr("ERROR: failed to start.  Couldn't create window\n");
  301.  
  302.             /* Lose the App* message port.
  303.              */
  304.             if (app_port)
  305.                 DeleteMsgPort(app_port);
  306.         }
  307.         else
  308.             PutStr("ERROR: failed to start.  Couldn't create layout\n");
  309.  
  310.         if (drinfo)
  311.             FreeScreenDrawInfo(screen, drinfo);
  312.  
  313.         UnlockPubScreen(0, screen);
  314.     }
  315.     else
  316.         PutStr("ERROR: failed to start.  Couldn't lock destination screen\n");
  317.  
  318.     exit(0);
  319. }
  320.